<?php
namespace app\common\models;

use app\common\service\AdminLogin;
use think\Model;
/**
 * BaseModel.php
 * @author: xujianping(814876569@qq.com)
 * @datetime: 2017/9/25 上午 9:50
 */
class BaseModel extends Model
{

    /**
     * 后台获取用户id
     * @return array
     */
    public function getAdminCreateBy(){
        $adminLogin = new AdminLogin();
        return $adminLogin->getUid();
    }


    public function getPageData ($where = ['status'=>1],$pageSize = 20) {
        return $this->where($where)->order('create_time DESC')->paginate($pageSize);
    }

    public function addDataByField($data,$allowField = true){
        return self::allowField($allowField)->save($data);
    }

    public function getDataById($id,$where = []){
        return self::where('id',$id)->where($where)->find();
    }

    public function updateDataById($id,$data,$where = []){
        return self::allowField(true)->where('id',$id)->where($where)->update($data);
    }

    public function deleteDataById($id){
        return self::where('id',$id)->update(['status'=>0]);
    }



    public function getOne($where = [], $order = ''){
        return self::where($where)->order($order)->find();
    }

    public function getMany($where = [], $order = ''){
        return self::where($where)->order($order)->select();
    }

}